package com.example.allplan.RecyclerAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.allplan.JavaBean.YiGeChouQian;
import com.example.allplan.R;

import java.util.ArrayList;

public class ChouQianLieBiaoAdapter extends RecyclerView.Adapter<ChouQianLieBiaoAdapter.ViewHolder> {
    ArrayList<YiGeChouQian> mList;
    ChouQianLieBiaoAdapter.onItemClickListener mListener;
    Context mcon;

    public ChouQianLieBiaoAdapter(ArrayList<YiGeChouQian> m, ChouQianLieBiaoAdapter.onItemClickListener mL, Context mcon) {
        mListener = mL;
        mList = m;
        this.mcon = mcon;
    }


    public interface onItemClickListener {
        void onClick(int pos, Context mcon);
    }

    public ChouQianLieBiaoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.yi_ge_chou_qian_item_view, parent, false);
        return new ChouQianLieBiaoAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ChouQianLieBiaoAdapter.ViewHolder holder, final int position) {
        holder.ming_cheng_textview.setText(mList.get(position).getMing_cheng());
        holder.item_linear_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onClick(holder.getAdapterPosition(), mcon);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView ming_cheng_textview;
        LinearLayout item_linear_view;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ming_cheng_textview = itemView.findViewById(R.id.xian_shi_ming_cheng_textview);
            item_linear_view = itemView.findViewById(R.id.xian_shi_gen_view);
        }

    }
}
